
<%@page import="javax.portlet.RenderResponse"%>
<%
/**
 * Copyright (c) 2000-2011 Liferay, Inc. All rights reserved.
 *
 * This library is free software; you can redistribute it and/or modify it under
 * the terms of the GNU Lesser General Public License as published by the Free
 * Software Foundation; either version 2.1 of the License, or (at your option)
 * any later version.
 *
 * This library is distributed in the hope that it will be useful, but WITHOUT
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
 * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
 * details.
 */
%>

<%@ include file="/html/portlet/login/init.jsp" %>
   
<%--@ page import="com.college.service.UniversityLocalServiceUtil" --%>

<%--  <%
	int count = UniversityLocalServiceUtil.getService().getUniversitiesCount();
	List list =UniversityLocalServiceUtil.getUniversities(0,count);
	
	System.out.println("list>>>>>>>>>>>>>>>"+list);
%>  --%>
<style type="text/css">
#submit {
	display:none;
}
		* { font-family: Verdana; font-size: 100%; }
		label { width: 10em; float: left; }
		label.error { float: none; color: red; padding-left: .5em; vertical-align: top; }
		p { clear: both; }
		.submit { margin-left: 12em; }
		em { font-weight: bold; padding-right: 1em; vertical-align: top; }
</style>
<aui:script>
	Liferay.provide(
			window,
			'callPopup',
			function(popUrl) {
				var A = AUI();
	
				var data = {};
	
				var dialog = new A.Dialog(
					{
						centered: true,
						destroyOnClose: true,
						draggable: true,
						height: 350,
						width: 350,
						resizable: false,
						modal: true,
						title: Liferay.Language.get('Terms and Conditions')
					}
					).render();
						dialog.plug(
							A.Plugin.IO,
							{
								data: data,
								uri: popUrl
							}
						);
				},
			['aui-dialog', 'aui-io']
	);
	</aui:script>
<script type="text/javascript" src="http://code.jquery.com/jquery-1.6.1.min.js"></script>
<script type="text/javascript" src="http://ajax.aspnetcdn.com/ajax/jquery.validate/1.8.1/jquery.validate.js"></script>

<script type="text/javascript">
	jQuery(document).ready(function(){
		jQuery("#select").css("display","block");
		jQuery("#req-details").css("display","none");  
		jQuery("#student").css("display","none");
		
		var option = jQuery('#<portlet:namespace/>middleName option[selected]').val(); 
		
		if(option=="student") { 
			jQuery("label[for=<portlet:namespace/>firstName]").html("Your Name");
			jQuery("#student").css("display","block");
			jQuery("#college").css("display","none");
			jQuery("#req-details").css("display","block");
			jQuery("#submit").css("display","block");
		} else if(option=="organization") {	
			jQuery("label[for=<portlet:namespace/>firstName]").html("Organization Name");
			jQuery("label[for=<portlet:namespace/>firstName]").attr("Organization Name");
			jQuery("#student").css("display","none");
			jQuery("#college").css("display","block");
			jQuery("#req-details").css("display","block");
			jQuery("#submit").css("display","block");
		} else{
			jQuery("#select").css("display","block");
			jQuery("#req-details").css("display","none");
			jQuery("#submit").css("display","none");
			jQuery("#college").css("display","none");
			jQuery("#student").css("display","none");
		}
		
		jQuery("#<portlet:namespace/>termsCheckbox").addClass("required");
		//jQuery("#<portlet:namespace/>middleName").addClass("required");
		//jQuery("#<portlet:namespace/>emailAddress").addClass("required email");
		
	}); 
		
	function registerClicked(){
		if(jQuery("#<portlet:namespace/>fm").validate().form()){
			jQuery("#<portlet:namespace/>fm").submit();
		} else {
			return false;
		}
	}
	
	function showDiv(option){
		jQuery("#select").css("display","none");
		jQuery("#req-details").css("display","block");
		jQuery("#submit").css("display","block");
		jQuery("#college").css("display","none");
		 
		if(option=="student") { 
			jQuery("label[for=<portlet:namespace/>element1]").html("Your Name");
			jQuery("#student").css("display","block");
			jQuery("#college").css("display","none");
			
			jQuery("#<portlet:namespace/>element2").removeAttr("name");
			jQuery("#<portlet:namespace/>element2").attr("name","<portlet:namespace/>dummy");
			
			jQuery("#<portlet:namespace/>element1").removeAttr("name");
			jQuery("#<portlet:namespace/>element1").attr("name","<portlet:namespace/>firstName");
			
		} else if(option=="organization") {	
			
			jQuery("label[for=<portlet:namespace/>element1]").html("Organization Name");
			
			jQuery("#<portlet:namespace/>element2").removeAttr("name");
			jQuery("#<portlet:namespace/>element2").attr("name","<portlet:namespace/>firstName");
			jQuery("#<portlet:namespace/>element1").removeAttr("name");
			jQuery("#<portlet:namespace/>element1").attr("name","<portlet:namespace/>openId");
			
			jQuery("#student").css("display","none");
			jQuery("#college").css("display","block");

		} else{
			jQuery("#select").css("display","block");
			jQuery("#req-details").css("display","none");
			jQuery("#submit").css("display","none");
			jQuery("#college").css("display","none");
			jQuery("#student").css("display","none");
		}
	} 
</script>
<%
String redirect = ParamUtil.getString(request, "redirect");

String openId = ParamUtil.getString(request, "openId");

User user2 = null;
Contact contact2 = null;

String middleName= ParamUtil.getString(request, "middleName");
String jobTitle= ParamUtil.getString(request, "jobTitle");

PasswordPolicy passwordPolicy = PasswordPolicyLocalServiceUtil.getDefaultPasswordPolicy(company.getCompanyId());

Calendar birthday = CalendarFactoryUtil.getCalendar();

birthday.set(Calendar.MONTH, Calendar.JANUARY);
birthday.set(Calendar.DATE, 1);
birthday.set(Calendar.YEAR, 1970);

boolean male = BeanParamUtil.getBoolean(contact2, request, "male", true);


String studentName= middleName!=null && middleName.equalsIgnoreCase("student")?"firstName":"openId";
String organizationName= middleName!=null && middleName.equalsIgnoreCase("organization")?"firstName":"dummy";

%>  
<portlet:actionURL var="createAccoutURL"> 
	<portlet:param name="saveLastPath" value="0" />
	<portlet:param name="struts_action" value="/login/create_account" />
</portlet:actionURL>
  
<aui:form action="<%= createAccoutURL %>" method="post" name="fm">
		<aui:input name="<%= Constants.CMD %>" type="hidden" value="<%= Constants.ADD %>" />
		<aui:input name="redirect" type="hidden" value="<%= redirect %>" />
		<%-- <aui:input name="openId" type="hidden" value="<%= openId %>" />--%>
		<liferay-ui:error exception="<%= AddressCityException.class %>" message="please-enter-a-valid-city" />
		<liferay-ui:error exception="<%= AddressStreetException.class %>" message="please-enter-a-valid-street" />
		<liferay-ui:error exception="<%= AddressZipException.class %>" message="please-enter-a-valid-zip" />
		<liferay-ui:error exception="<%= CaptchaTextException.class %>" message="text-verification-failed" />
		<liferay-ui:error exception="<%= CompanyMaxUsersException.class %>" message="unable-to-create-user-account-because-the-maximum-number-of-users-has-been-reached" />
		<liferay-ui:error exception="<%= ContactFirstNameException.class %>" message="please-enter-a-valid-name" />
		<liferay-ui:error exception="<%= ContactFullNameException.class %>" message="please-enter-a-valid-first-middle-and-last-name" />
		<liferay-ui:error exception="<%= ContactLastNameException.class %>" message="please-enter-a-valid-last-name" />
		<liferay-ui:error exception="<%= DuplicateUserEmailAddressException.class %>" message="the-email-address-you-requested-is-already-taken" />
		<liferay-ui:error exception="<%= DuplicateUserIdException.class %>" message="the-user-id-you-requested-is-already-taken" />
		<liferay-ui:error exception="<%= DuplicateUserScreenNameException.class %>" message="the-screen-name-you-requested-is-already-taken" />
		<liferay-ui:error exception="<%= EmailAddressException.class %>" message="please-enter-a-valid-email-address" />
		<liferay-ui:error exception="<%= NoSuchCountryException.class %>" message="please-select-a-country" />
		<liferay-ui:error exception="<%= NoSuchListTypeException.class %>" message="please-select-a-type" />
		<liferay-ui:error exception="<%= NoSuchRegionException.class %>" message="please-select-a-region" />
		<liferay-ui:error exception="<%= PhoneNumberException.class %>" message="please-enter-a-valid-phone-number" />
		<liferay-ui:error exception="<%= RequiredFieldException.class %>" message="please-fill-out-all-required-fields" />
		<liferay-ui:error exception="<%= ReservedUserEmailAddressException.class %>" message="the-email-address-you-requested-is-reserved" />
		<liferay-ui:error exception="<%= ReservedUserIdException.class %>" message="the-user-id-you-requested-is-reserved" />
		<liferay-ui:error exception="<%= ReservedUserScreenNameException.class %>" message="the-screen-name-you-requested-is-reserved" />
		<liferay-ui:error exception="<%= TermsOfUseException.class %>" message="you-must-agree-to-the-terms-of-use" />
		<liferay-ui:error exception="<%= UserEmailAddressException.class %>" message="please-enter-a-valid-email-address" />
		<liferay-ui:error exception="<%= UserIdException.class %>" message="please-enter-a-valid-user-id" />
	
		<liferay-ui:error exception="<%= UserPasswordException.class %>">
	
			<%
			UserPasswordException upe = (UserPasswordException)errorException;
			%>
	
			<c:if test="<%= upe.getType() == UserPasswordException.PASSWORD_CONTAINS_TRIVIAL_WORDS %>">
				<liferay-ui:message key="that-password-uses-common-words-please-enter-in-a-password-that-is-harder-to-guess-i-e-contains-a-mix-of-numbers-and-letters" />
			</c:if>
	
			<c:if test="<%= upe.getType() == UserPasswordException.PASSWORD_INVALID %>">
				<liferay-ui:message key="that-password-is-invalid-please-enter-in-a-different-password" />
			</c:if>
	
			<c:if test="<%= upe.getType() == UserPasswordException.PASSWORD_LENGTH %>">
				<%= LanguageUtil.format(pageContext, "that-password-is-too-short-or-too-long-please-make-sure-your-password-is-between-x-and-512-characters", String.valueOf(passwordPolicy.getMinLength()), false) %>
			</c:if>
	
			<c:if test="<%= upe.getType() == UserPasswordException.PASSWORDS_DO_NOT_MATCH %>">
				<liferay-ui:message key="the-passwords-you-entered-do-not-match-each-other-please-re-enter-your-password" />
			</c:if>
		</liferay-ui:error>
	
		<liferay-ui:error exception="<%= UserScreenNameException.class %>" message="please-enter-a-valid-screen-name" />
		<liferay-ui:error exception="<%= WebsiteURLException.class %>" message="please-enter-a-valid-url" />
	
		<c:if test='<%= SessionMessages.contains(request, "missingOpenIdUserInformation") %>'>
			<div class="portlet-msg-info">
				<liferay-ui:message key="you-have-successfully-authenticated-please-provide-the-following-required-information-to-access-the-portal" />
			</div>
		</c:if>
	
		<aui:model-context bean="<%= contact2 %>" model="<%= Contact.class %>" />
		
	<h2 id="select">Please select one of the options.</h2>

	<aui:fieldset>
			<aui:column>
			<aui:select label="I belong To" name="middleName" onchange="showDiv(this.value)">
				<aui:option label="select" value="select" />
				<aui:option label="Student" value="student" selected="<%= middleName.equals(\"student\") %>"/>
				<aui:option label="Organization" value="organization" selected="<%= middleName.equals(\"organization\") %>"/>
			</aui:select>
			
			<div id="req-details">
				<aui:input type="text" id="element1" name="<%= studentName %>" label="Your Name" /> 
				<aui:input bean="<%= user2 %>" model="<%= User.class %>" name="emailAddress" />
			</div>		
				<div id="student">	
					<c:choose>
						<c:when test="<%= PrefsPropsUtil.getBoolean(company.getCompanyId(), PropsKeys.FIELD_ENABLE_COM_LIFERAY_PORTAL_MODEL_CONTACT_BIRTHDAY) %>">
							<aui:input name="birthday" value="<%= birthday %>" />
						</c:when>
						<c:otherwise>
							<aui:input name="birthdayMonth" type="hidden" value="<%= Calendar.JANUARY %>" />
							<aui:input name="birthdayDay" type="hidden" value="1" />
							<aui:input name="birthdayYear" type="hidden" value="1970" />
						</c:otherwise>
					</c:choose>
					
					<c:if test="<%= PrefsPropsUtil.getBoolean(company.getCompanyId(), PropsKeys.FIELD_ENABLE_COM_LIFERAY_PORTAL_MODEL_CONTACT_MALE) %>">
						<aui:select label="gender" name="male">
							<aui:option label="male" value="1" />
							<aui:option label="female" selected="<%= !male %>" value="0" />
						</aui:select>
					</c:if>

					<c:if test="<%= PropsValues.LOGIN_CREATE_ACCOUNT_ALLOW_CUSTOM_PASSWORD %>">
						<aui:input label="password" name="password1" size="30" type="password" value="" />
		
						<aui:input label="enter-again" name="password2" size="30" type="password" value="" />
					</c:if>
				</div>

			<%
			 String[] organizationsTypes = com.liferay.portal.kernel.util.PropsUtil.getArray("organizations.types");
			%>
			
			<div id="college">
			<!-- openId used for contact person name -->
				<aui:input type="text" name="<%= organizationName %>" label="Contact Person" id="element2" />
				<aui:select label="organization Type" name="jobTitle" >
					<aui:option label="select" value="select" />
					<%
					for(String type : organizationsTypes) {
					%>
						<aui:option label="<%= type %>" value="<%= type %>" selected="<%= jobTitle.equals(type) %>" />
					<% } %>
				</aui:select>
				<c:if test="<%= PrefsPropsUtil.getBoolean(company.getCompanyId(), PropsKeys.FIELD_ENABLE_COM_LIFERAY_PORTAL_MODEL_CONTACT_MALE) %>">
						<aui:select label="gender" name="male">
							<aui:option label="male" value="1" />
							<aui:option label="female" selected="<%= !male %>" value="0" />
						</aui:select>
				</c:if>
			</div>
	
			<div id="submit">
				<c:if test="<%= PropsValues.CAPTCHA_CHECK_PORTAL_CREATE_ACCOUNT %>">
						<portlet:actionURL windowState="<%= LiferayWindowState.EXCLUSIVE.toString() %>" var="captchaURL">
							<portlet:param name="struts_action" value="/login/captcha" />
						</portlet:actionURL>
						<liferay-ui:captcha url="<%= captchaURL %>" />
				</c:if>
			<div>
				<portlet:renderURL var="newSearchURL" windowState="<%= LiferayWindowState.EXCLUSIVE.toString() %>">
					<portlet:param name="jspPage" value=" /html/portal/terms_of_use.jsp"/>
				</portlet:renderURL>
				<aui:input type="checkbox" id="terms" label=" " name="terms"/><a href="javascript:void(0)" onclick="callPopup('<%= newSearchURL.toString() %>')" >Terms and Conditions</a>
				<aui:button-row>    
						<aui:button type="button" value="Register" onclick="registerClicked();"/>
				</aui:button-row>
			</div>
			</div>
		</aui:column>   
	</aui:fieldset>
</aui:form>	


	<liferay-util:include page="/html/portlet/login/navigation.jsp" />

<c:if test="<%= windowState.equals(WindowState.MAXIMIZED) %>">
	<aui:script>
		Liferay.Util.focusFormField(document.<portlet:namespace />fm.<portlet:namespace />InstitutionName);
	</aui:script>
</c:if>